package gameEngine.agents.distrebution.representation;

import org.apache.log4j.Logger;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;


public class ExponentialRepresentation extends DistributionRepresentation{

	Logger log = Logger.getLogger(this.getClass());
	
	//protected String 	distributionName = null;
	private 	double 	lambda = 0;
	
	/**
	 * CTOR
	 */
	public ExponentialRepresentation (String name, double lambda)
	{
		this.distributionName	= name;
		this.lambda				= lambda;
	}

	/**
	 * CTOR
	 * Designed for Open XML procedure
	 */
	public ExponentialRepresentation (String name)
	{
		this.distributionName = name;
	}
	
	public double getLambda() {
		return lambda;
	}

	public void setLambda(double lambda) {
		this.lambda = lambda;
	}
	

	@Override
	public void setExtraElement(Document doc, Element distribution) {
		//lambda 
		Element lambda = doc.createElement("Lambda");
		lambda.appendChild(doc.createTextNode(Double.toString(this.lambda)));
		
		distribution.appendChild(lambda);		
	}

	/** Set this distribution data from XML  */
	public void  openExtraDistributionData(Document doc, Element distElement)
	{
		NodeList list = distElement.getElementsByTagName("Lambda");
		Element lambdaElement = (Element)list.item(0); 
		//take the text value of lambda
		String 	lambdaStr = getTagValue(lambdaElement.getNodeName(), distElement);
		double  lambda = Double.parseDouble(lambdaStr);
		log.debug("Lambda value in the XML is " + lambda);
		this.lambda = lambda;
	}
	
}
